window.onload = function () {
    var cms_swiper = document.getElementById('cms-banner-swiper');
    var cms_swiperItem = document.getElementsByClassName('swiperItem');
    var cms_points = document.querySelectorAll('.cms-banner-left h4');
    var cms_btnPre = document.querySelector('.cms-pre');
    var cms_btnNext = document.querySelector('.cms-next');
    var cms_index = 0;
    var cms_timer;
    swiperPlay()
   

    function swiperPlay() {
        cms_index++;
        if (cms_index > cms_swiperItem.length - 1) {
            cms_index = 0;
        }
        changeImg()

    }

    function changeAll() {
        changeImg();
        changePoint();

    }

    function changeImg() {
        for (var i = 0; i < cms_swiperItem.length; i++) {
            cms_swiperItem[i].className = "swiperItem def";
        }
        if (cms_index === 0) {
            cms_swiperItem[cms_index].className = "swiperItem b";
            cms_swiperItem[cms_swiperItem.length - 1].className = "swiperItem a";
            cms_swiperItem[cms_index + 1].className = "swiperItem c";
        } else if (cms_index === cms_swiperItem.length - 1) {
            cms_swiperItem[cms_index].className = "swiperItem b";
            cms_swiperItem[cms_index-1].className = "swiperItem a";
            cms_swiperItem[0].className = "swiperItem c";
        } else {
            cms_swiperItem[cms_index].className = "swiperItem b";
            cms_swiperItem[cms_index-1].className = "swiperItem a";
            cms_swiperItem[cms_index + 1].className = "swiperItem c";
        }
    }
    function changePoint(){
         for (var i = 0; i < cms_points.length; i++) {
            cms_points[i].className = 'cms-hidden';
            }
            cms_points[cms_index].className = 'cms-show';
    }
    for (var i = 0; i < cms_points.length; i++) {
        cms_points[i].index = i;
        cms_points[i].onmouseenter = function () {
            cms_index = this.index;
            changeAll();
        }

    }

    cms_btnPre.onclick=function(){
        cms_index--;
        if(cms_index<0){
            cms_index=cms_swiperItem.length-1;
        }
        changeAll()
    }
    cms_btnNext.onclick=function(){
        cms_index++;
        if(cms_index>cms_swiperItem.length-1){
            cms_index=0;
        }
        changeAll()
    }


    // var startX = 0;
    // var moveX = 0;
    // console.log(mousedragged());
    // cms_swiper.addEventListener('mousedragged',function (e) {
    //     startX = e.targetTouches[0].pageX;
    //     console.log(1);
    // })
    
    // cms_swiper.addEventListener('touchmove',function(e){
    //     moveX = e.targetTouches[0].pageX - startX;
    //     var translateX = 
    // })

}

